package com.mantou.mantouaiagent.task;

import com.mantou.mantouaiagent.config.chatmemory.RedisChatMemory;
import com.mantou.mantouaiagent.mapper.HistoryMapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.messages.Message;
import org.springframework.boot.autoconfigure.cache.CacheProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.DeleteMapping;

import java.util.Set;

/**
 * @Author: 馒头
 * @CreateTime: 2025-06-02
 * @Description:
 */
@Component
@Slf4j
public class RedisCacheTask {

    @Resource
    private RedisTemplate<String, Message> messageRedisTemplate;

    @Resource
    private HistoryMapper historyMapper;

    private static final String REDIS_KEY_PREFIX ="CHAT_MEMORY";

    /**
     * 刷新每日用户使用次数
     */
    @Scheduled(cron = "0 0 0 * * ?", zone = "Asia/Shanghai")
//    @Scheduled(cron = "0 0/1 * * * ?")
    public void deleteCache() {
         System.out.println("开始删除缓存");
        Set<String> ip = messageRedisTemplate.keys("ip:"+"*");
        messageRedisTemplate.delete(ip);
    }
}
